package com.simple.demo.io;

import java.io.*;

public class IOStream {

    public static void main(String[] args) {
        t2();


    }

    private static  void t2(){
        StringReader sr = null;
        StringWriter sw = null;
try{
    sr = new StringReader("sdfdsfdsfdsfdsf");
    sw = new StringWriter();
    int readLen = 0 ;
    char [] chararray = new char[1];
    while((readLen = sr.read(chararray)) > 0){
        String s = new String(chararray, 0, readLen);
         System.out.println(s);
         sw.write(s);
    }
    sr.close();
    sw.flush();
    sw.close();
    System.out.println(sw.toString());
        }catch (Exception c){
    c.printStackTrace();
        }

    }

    private  static void t1(){
        OutputStream out = null;
        InputStream in = null;

        try {
            in = new FileInputStream("D:\\tmp\\0601\\out.txt");
            out = new FileOutputStream("D:\\tmp\\0601\\out1.txt");
            byte [] buffer = new byte[100];
            int readLen = 0 ;
            while ((readLen = in.read(buffer)) > 0){
                out.write(buffer, 0, readLen);
            }
            System.out.println("write is success!");
            out.close();
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
